package java8.chapter10.test;

import static java.util.Optional.empty;
import static java.util.Optional.of;

import java.util.Optional;

public class OperationsWithOptional {

	public static void main(String[] args) {
		System.out.println(max(of(3), of(5)));
		System.out.println(max(empty(), of(5)));
	}

	private static final Optional<Integer> max(Optional<Integer> i, Optional<Integer> j) {
		return i.flatMap(a -> j.map(b -> Math.max(a, b)));
	}

}